﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace MyFloridaHouse.libSvUtilities
{
    public static class SerializationManager
    {
        public static byte[] Serialize(Object obj)
        {
            Type type = obj.GetType();
            DataContractSerializer dcs = new DataContractSerializer(type);
            using (var memStream = new MemoryStream())
            {
                dcs.WriteObject(memStream, obj);
                return memStream.ToArray();
            }
        }

        public static Object Deserialize(Type type, byte[] objectData)
        {
            DataContractSerializer dcs = new DataContractSerializer(type);
            using (var memStream = new MemoryStream(objectData))
            {
                return dcs.ReadObject(memStream);
            }
        }
    }
}
